<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace app\wechat\controller\admin;

use app\admin\common\AdminController;

class Config extends AdminController
{
    public function index()
    {
        if (request()->isPost()) {
            $module_info = model('admin/module')->where('name', 'wechat')->findOrFail();
            $config_list = $module_info['config'] ? helper('admin/json')->decode($module_info['config']) : array();
            $config_list = array_merge($config_list, $this->post_array());
            $module_info['config'] = helper('admin/json')->encode($config_list);

            if ($module_info->save() !== false) {
                cache(null);
                $this->success('修改成功。', $this->url('index'));
            }
        }

        $this->display('admin/config/config_form');
    }
}